<template>
	<view class="page">
		<view class="tab">
			<text 
				v-for="v in tabs" 
				:key="v.key" 
				:class="{'tab-active' : v.key === current}"
				@click="tabChange(v)"
			>
				{{v.name}}
			</text>
		</view>
		<view class="ranking">
			<view class="rangking-title">
				<text>排名</text>
				<text>昵称</text>
				<text>时长(h)</text>
			</view>
			<view class="ranking-list">
				<view class="ranking-list-item" v-for="(item, key) in list" :key="key">
					<view class="ranking-list-number">
						<text>{{key + 1}}</text>
					</view>
					<view class="ranking-list-nickname">
						<text>{{item.username}}</text>
					</view>
					<text class="ranking-list-score">{{item.clockSum}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		rankList,
	} from '@/api/member.js'
	

	export default {
		data(){
			return {
				current: 1,
				tabs: [
					{name: '日榜', key: 1},
					{name: '周榜', key: 2},
					{name: '月榜', key: 3}
				],
				list: [] // 排行榜
			}
		},
		onLoad() {
			this.searchRankList()
		},
		methods:{
			tabChange(e){
				this.current = e.key;
				this.searchRankList();
				console.log(e);
			},
			// 排行榜
			// 查询
			searchRankList() {
				rankList({
					type: this.current
				}).then(res => {
					this.list = res.data
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #3F51B5;
	}
	
	.page{
		padding-bottom: 20rpx;
		
		.tab{
			width: 700rpx;
			margin: auto;
			display: flex;
			justify-content: center;
			align-items: flex-end;
			padding: 25rpx;
			
			text{
				display: block;
				width: 120rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				color: #fff;
				font-size: 14px;
			}
			
			.tab-active{
				font-size: 16px;
				font-weight: bold;
				position: relative;
				
				&::after{
					content: '';
					width: 40rpx;
					height: 6rpx;
					border-radius: 4rpx;
					background: #fff;
					position: absolute;
					left: 40rpx;
					bottom: 0;
				}
			}
			
		}
		
		.ranking{
			width: 700rpx;
			border-radius: 30rpx;
			margin: auto;
			box-sizing: border-box;
			padding: 20rpx;
			
			.rangking-title{
				display: flex;
				font-size: 12px;
				color: #f0f0f0;
				height: 50rpx;
				line-height: 50rpx;
				
				text{
					display: block;
					width: 100rpx;
					text-align: center;
					
					&:nth-child(2){
						box-sizing: border-box;
						padding-left: 20rpx;
						text-align: left;
						width: calc(100% - 200rpx);
					}
				}
			}
			
			.ranking-list-item{
				height: 110rpx;
				border-radius: 20rpx;
				display: flex;
				align-items: center;
				font-size: 14px;
				background: rgba(255, 255, 255, 0.7);
				margin: 16rpx 0;
				
				&:nth-child(1){
					background: #efb300;
				}
				
				&:nth-child(2){
					background: #b4b0b0;
				}
				
				&:nth-child(3){
					background: #e37d19;
				}
				
				.ranking-list-number{
					width: 100rpx;
					color: #777;
					display: flex;
					justify-content: center;
					
					image{
						width: 50rpx;
						height: 50rpx;
					}
				}
				
				.ranking-list-score{
					display: block;
					width: 100rpx;
					color: #555;
					font-size: 16px;
					text-align: center;
				}
				
				.ranking-list-nickname{
					display: flex;
					align-items: center;
					width: calc(100% - 200rpx);
					box-sizing: border-box;
					padding-left: 20rpx;
					
					image{
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
						margin-right: 20rpx;
					}
					
					text{
						width: auto;
					}
				}
			}
		}
	}
</style>